package com.pn.controller;

import com.pn.entity.Purchase;
import com.pn.entity.Result;
import com.pn.entity.Store;
import com.pn.page.Page;
import com.pn.service.PurchaseService;
import com.pn.service.StoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("purchase")
@RestController
public class PurchaseController {
    @Autowired
    private PurchaseService purchaseService;
    //注入StoreService
    @Autowired
    private StoreService storeService;

    /**
     * 添加采购的URL接口 /purchase/purchase-add
     *
     * @param purchase 采购单表信息
     * @return 添加结果
     */
    @RequestMapping("/purchase-add")
    public Result addPurchase(@RequestBody Purchase purchase) {
        return purchaseService.savePurchase(purchase);
    }

    /**
     * 查询所有仓库的 url 接口/purchase/store-list
     */
    @RequestMapping("/store-list")
    public Result storeList() {
//执行业务
        List<Store> storeList = storeService.queryAllStore();
//响应
        return Result.ok(storeList);
    }

    /**
     * 分页查询采购单的 url 接口/purchase/purchase-page-list
     * <p>
     * 参数 Page 对象用于接收请求参数页码 pageNum、每页行数 pageSize;
     * 参数 Purchase 对象用于接收请求参数仓库 id storeId、商品名称 productName、
     * 采购人 buyUser、是否生成入库单 isIn、起止时间 startTime 和 endTime;
     * <p>
     * 返回值 Result 对象向客户端响应组装了所有分页信息的 Page 对象;
     */
    @RequestMapping("/purchase-page-list")
    public Result purchasePageList(Page page, Purchase purchase) {
//执行业务
        page = purchaseService.queryPurchasePage(page, purchase);
//响应
        return Result.ok(page);
    }
}
